package Thread;

//饿汉式单例
class Singleton {
    private static Singleton instance = new Singleton();
    public static Singleton getSingleton() {
        return instance;
    }
    private Singleton() {
        //防止反射攻击
    }
}
public class Demo1 {
    public static void main(String[] args) {
        Singleton instance = Singleton.getSingleton();
        Singleton instance2 = Singleton.getSingleton();
        System.out.println(instance2 == instance);
    }
}
